<template>
	<el-card class="layout-query">
		<el-form ref="queryRef" :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
			<el-form-item prop="sendCountry">
				<el-input v-model="state.queryForm.sendCountry" placeholder="发货地（国家）"></el-input>
			</el-form-item>
			<el-form-item prop="sendProvince">
				<el-input v-model="state.queryForm.sendCity" placeholder="发货地（州）"></el-input>
			</el-form-item>
			<el-form-item prop="sendCity" class="send-city-item">
				<el-input v-model="state.queryForm.sendProvince" placeholder="发货地（城市）"></el-input>
			</el-form-item>
			<el-row>
				<el-form-item prop="orderStatus">
					<ma-dict-select v-model="state.queryForm.orderStatus" dict-type="order_status" placeholder="分类"></ma-dict-select>
				</el-form-item>
			</el-row>
			<el-form-item prop="sendCity">
				<el-input v-model="state.queryForm.sendCity" placeholder="目的地(城市)"></el-input>
			</el-form-item>
			<el-form-item prop="goalCountry">
				<el-input v-model="state.queryForm.goalCountry" placeholder="目的地（国家）"></el-input>
			</el-form-item>
			<el-form-item prop="goalProvince">
				<el-input v-model="state.queryForm.sendProvince" placeholder="目的地（州）"></el-input>
			</el-form-item>
			<el-form-item prop="catalog">
				<el-input v-model="state.queryForm.catalog" placeholder="分类"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button icon="Search" type="primary" @click="getDataList()">查询</el-button>
			</el-form-item>
			<el-form-item>
				<el-button icon="RefreshRight" @click="reset(queryRef)">重置</el-button>
			</el-form-item>
		</el-form>
	</el-card>

	<el-card>
		<el-space>
			<el-space>
				<el-button v-auth="'danhao:mainOrder:update'" icon="Plus" plain type="primary" @click="buyBatchHandle()">批量购买</el-button>
			</el-space>
		</el-space>
		<el-table v-loading="state.dataListLoading" :data="state.dataList" border class="layout-table" @selection-change="selectionChangeHandle">
			<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
			<el-table-column prop="orderNumber" label="订单编号" header-align="center" align="center"></el-table-column>
			<el-table-column prop="sendCountry" label="发货地（国家）" header-align="center" align="center"></el-table-column>
			<el-table-column prop="sendProvince" label="发货地(州)" header-align="center" align="center"></el-table-column>
			<el-table-column prop="sendCity" label="发货地(城市)" header-align="center" align="center"></el-table-column>
			<el-table-column prop="goalCountry" label="目的地(城市)" header-align="center" align="center"></el-table-column>
			<el-table-column prop="goalProvince" label="目的地(州)" header-align="center" align="center"></el-table-column>
			<el-table-column prop="goalCity" label="目的地(城市)" header-align="center" align="center"></el-table-column>
			<el-table-column prop="sendTime" label="发货时间" header-align="center" align="center"></el-table-column>
			<el-table-column prop="remark" label="备注" header-align="center" align="center"></el-table-column>
			<el-table-column prop="price" label="价格" header-align="center" align="center"></el-table-column>
			<ma-dict-column prop="catalog" dict-type="order_status" label="类型" header-align="center" align="center"></ma-dict-column>
			<el-table-column prop="orderStatus" label="单号状态" header-align="center" align="center"></el-table-column>
			<el-table-column prop="createTime" label="上传时间" header-align="center" align="center"></el-table-column>
			<el-table-column prop="buyStatus" label=" 购买状态" header-align="center" align="center"></el-table-column>
			<el-table-column label="" fixed="right" header-align="center" align="center" width="150">
				<template #default="scope">
					<el-button v-auth="'danhao:mainOrder:update'" type="primary" link @click="addOrUpdateHandle(scope.row.id)">购买</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination
			:current-page="state.page"
			:page-sizes="state.pageSizes"
			:page-size="state.limit"
			:total="state.total"
			layout="total, sizes, prev, pager, next, jumper"
			@size-change="sizeChangeHandle"
			@current-change="currentChangeHandle"
		>
		</el-pagination>

		<!-- 弹窗, 新增 / 修改 -->
		<add-or-update ref="addOrUpdateRef" @refresh-data-list="getDataList"></add-or-update>
	</el-card>
</template>

<script setup lang="ts" name="DanhaoMainOrderIndex">
import { useCrud } from '@/hooks'
import { reactive, ref } from 'vue'
import { IHooksOptions } from '@/hooks/interface'
import AddOrUpdate from './add-or-update.vue'

const state: IHooksOptions = reactive({
	dataListUrl: '/danhao/mainOrder/page',
	buyUrl: '/danhao/mainOrder/buyList',
	queryForm: {
		orderNumber: '',
		sendCountry: '',
		sendProvince: '',
		sendCity: '',
		goalCountry: '',
		goalProvince: '',
		goalCity: '',
		sendTime: '',
		orderStatus: '',
		price: '',
		catalog: '',
		remark: '',
		orgId: ''
	}
})

const queryRef = ref()
const addOrUpdateRef = ref()
const addOrUpdateHandle = (id?: number) => {
	addOrUpdateRef.value.init(id)
}

const handleClick = (orgId: any[]) => {
	state.queryForm.orgId = orgId
	getDataList()
}
const treeVisible = ref(false)

const { getDataList, selectionChangeHandle, sizeChangeHandle, currentChangeHandle, buyBatchHandle, reset } = useCrud(state)
</script>
